package com.chen.assist;

import java.util.concurrent.CountDownLatch;

// 计数器
public class SubtractCount {
    public static void main(String[] args) throws InterruptedException {

        // 计数器，参数是初始值
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "出去了");
                // 减
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }
        // 等待计数器归零，然后再向下执行
        countDownLatch.await();
        System.out.println("门闩上了");

    }
}
